package org.ant.util;

import java.net.URL;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.Vector;

/**
 *
 * @author hichens
 */
public class ResourceHandler {
    private  ResourceBundle resources;

    public ResourceHandler(String r){
        try {
            resources = ResourceBundle.getBundle(r);
        } catch (MissingResourceException mre) {
            System.err.println(r+".properties not found");
            System.exit(1);
        }
    }

    public String getResourceString(String nm) {
        String str;
        try {
            str = resources.getString(nm);
        } catch (MissingResourceException mre) {
            str = null;
        }
        return str;
    }

    public URL getResourceURL(String key) {
        String name = getResourceString(key);
        if (name != null) {
            URL url = this.getClass().getResource(name);
            return url;
        }
        return null;
    }
    
    public static String[] tokenize(String input) {
    	Vector v = new Vector();
    	StringTokenizer t = new StringTokenizer(input);
    	String cmd[];

    	while (t.hasMoreTokens())
    	    v.addElement(t.nextToken());
    	cmd = new String[v.size()];
    	for (int i = 0; i < cmd.length; i++)
    	    cmd[i] = (String) v.elementAt(i);

    	return cmd;
        }
}
